package com.design.singleton;

import java.util.concurrent.atomic.AtomicReference;

/**
 * CAS线程安全
 * @author ytj
 * @date 2024/11/27 15:42
 */
public class Singleton6 {
    private static final AtomicReference<Singleton6> reference=new AtomicReference<>();

    private Singleton6(){}

    public static Singleton6 getSingleton6(){
        while (true){
            Singleton6 singleton6 = reference.get();
            if(singleton6!=null){
                return singleton6;
            }
            reference.compareAndSet(null,new Singleton6());
            return reference.get();
        }
    }
}
